# coding = utf-8
# udp 通讯

import socket

udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.bind(('', 8081))
o_addr = ('172.20.10.8', 8080)
send_msg = 'hello world! 你好世界'
# str.encode('utf-8') 将bytes类型转为字符串
udp_socket.sendto(send_msg.encode('utf-8'), o_addr)
recv_data = udp_socket.recvfrom(1024)
# b'abc'.decode('utf-8') 将字符串转为bytes类型
print(recv_data[0].decode('utf-8'))
print(recv_data)
udp_socket.close()
